package dp;

/**
 * @author pengfei.hpf
 * @date 2020/3/2
 * @verdion 1.0.0
 */
public class MinCost {
    public int minCost(int[][] costs) {

        if(costs == null || costs.length == 0 || costs[0].length == 0){
            return 0;
        }
        int res = Integer.MAX_VALUE;
        for(int i = 0; i < costs.length; i ++){
            res = Integer.MAX_VALUE;
            for(int j = 0; j < costs[0].length; j ++){
                if(i > 0){
                    int min = Integer.MAX_VALUE;
                    for(int l = 0; l < costs[0].length; l ++){
                        if(l != j){
                            if(min > costs[i-1][l]){
                                min = costs[i - 1][l];
                            }
                        }
                    }
                    costs[i][j] += min;

                }
                if(costs[i][j] < res){
                    res = costs[i][j];
                }
            }
        }
        return res;
    }
}
